package org.foxas.ui
{
	import flash.events.TimerEvent;
	import flash.utils.setTimeout;
	import flash.utils.clearTimeout;
	import flash.utils.getTimer;
	
	public class FTag extends FTextList
	{
//		public var container:DisplayObjectContainer;
		public var maxWidth:Number;
		public var maxHeight:Number;
		public function FTag(_maxWidth:Number=0,_maxHeight:Number=0)//_container:DisplayObjectContainer=null)
		{
			super();
			this.mouseEnabled = false;
			this.mouseChildren = false;
			maxWidth = _maxWidth;
			maxHeight = _maxHeight;
//			if(_container){
//				container = this.stage;
//			}else{
//				container = _container;
//			}
		}
		public override function build(_x:int,_y:int,_valueArray:Array, _labelArray:Array=null):void{
			super.build(_x,_y,_valueArray, _labelArray);
			if(this.stage){
				posRefur(_x,_y);
			}else{
//				this.x = _x;
//				this.y = _y;
			}
			this.visible = true;
			clearTimeout(interval);
		}
		private var interval:uint;
		public function hidden(_bufferTime:int=0):void{
			interval = setTimeout(hidden_real,_bufferTime);
//			trace(getTimer());
		}
		private function hidden_real():void{
			clearTimeout(interval);
//			trace(getTimer());
			this.visible = false;
		}
		protected function posRefur(_x:int,_y:int):void{
//			_x = this.width;
//			_y -= this.height*0.5;
			if(maxWidth==0){
				this.maxWidth = this.stage.stageWidth;
			}
			if(this.maxHeight==0){
				this.maxHeight = this.stage.stageHeight;
			}
			if(this.maxWidth>= (this.width+_x)){
				this.x = _x;
			}else{
				this.x = this.maxWidth- this.width;
			}
			if(this.maxHeight >= (this.height+_y)){
				this.y = _y;
			}else{
				this.y = this.maxHeight - this.height;
			}
			this.x = Math.max(this.x,0);
			this.y = Math.max(this.y,0);
		}
	}
}